package com.wpl.controller;

import com.wpl.bean.Customer;
import com.wpl.common.WebResponse;
import com.wpl.service.ICustomerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 客户
 */
@RestController
@RequestMapping("/customer/")
public class CustomerController {

    @Resource
    private ICustomerService customerService;

    /**
     * 获取客户列表
     * @return
     */
    @GetMapping("/list")
    public WebResponse findAll(){
        List<Customer> customerList = customerService.findAll();
        return  WebResponse.success(customerList);
    }

    /**
     * 添加客户信息
     * @param customer
     * @return
     */
    @PostMapping("/add")
    public WebResponse addCustomer(@RequestBody Customer customer){
        int count = customerService.addCustomer(customer);
        if (count>0){
            return WebResponse.success(count);
        }else {
            return WebResponse.failed();
        }
    }

    /**
     *  根据ID查询客户信息
     * @param id
     * @return
     */
    @PostMapping("/queryid")
    public WebResponse findById( Integer id){
        Customer customer = customerService.findById(id);
        return WebResponse.success(customer);
    }
}


